package com.tancire.question.controller;

import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.member.domain.Member;
import com.tancire.question.domain.TrainProblem;
import com.tancire.question.domain.TrainProblemType;
import com.tancire.question.service.ITrainActivityService;
import com.tancire.question.service.ITrainProblemService;
import com.tancire.question.service.ITrainProblemTypeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 答题活动Controller
 *
 * @author tancire
 * @date 2024-10-10
 */
@RestController
@RequestMapping("/open/mobile/train")
public class TrainActivityOpenController extends BaseController {

    @Resource
    private ITrainProblemTypeService trainProblemTypeService;

    @Resource
    private ITrainActivityService trainActivityService;

    @Resource
    private ITrainProblemService trainProblemService;

    /**
     * 查询问题类型列表
     */
    @GetMapping("/types/list")
    public AjaxResult listAll() {
        List<TrainProblemType> list = trainProblemTypeService.selectTrainProblemTypeList(new TrainProblemType());
        return AjaxResult.success(list);
    }

    /**
     * 查询答题题目列表
     */
    @GetMapping("/problem/list")
    public AjaxResult problemList(TrainProblem trainProblem) {
        TrainProblem trainProblemRes = trainProblemService.selectNextProblem(trainProblem);
        return AjaxResult.success(trainProblemRes);
    }

    /**
     * 查询答题题目数量
     */
    @GetMapping("/problem/count")
    public AjaxResult problemCount(TrainProblem trainProblem) {
        Integer count = trainProblemService.selectProblemCount(trainProblem);
        return AjaxResult.success("查询数量成功", count);
    }

    /**
     * 查询排行榜
     */
    @GetMapping("/ranking/list")
    public AjaxResult rankingList() {
        List<Member> memberList = this.trainActivityService.getRankingList();
        return AjaxResult.success("查询排行榜成功", memberList);
    }
}
